<!--环保投入计划汇总表 RptInvestmentPlan-->
<template>
    <Layout class="menu-left">
        <Menu mode="horizontal" @on-select='lowerStep' :active-name="modaleShow">
            <MenuItem :name="1">本年度环保提升项目完成情况</MenuItem>
            <MenuItem :name="2">环保投入计划(次年及临时)</MenuItem>
        </Menu>
        <Form ref="queryForm" :model="dataToQuery" style="margin-top: 10px;" :label-width="120">
            <Row class="query-form" >
                <Col span="8">
                    <FormItem label='二级集团：' prop='belongOrgId'>
                        <Select class='query-form-el' v-model='dataToQuery.belongOrgId' label-in-value @on-change="belongChange">
                            <Option v-for="item in twoLevel" :value="item.orgId" :key="item.orgId">{{item.orgName}}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label='年度：' prop='yearDate'>
                        <DatePicker class="query-form-el" placeholder="请选择年度" v-model='dataToQuery.yearDate' type="year"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8" v-if="!switchFlag" >
                    <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
                    <Button @click="reset1" class="ivu-btn-reset">重置</Button>
                    <Button type="primary" class="ivu-btn-query" icon="md-search"  @click="query">查询</Button>
                </Col>
                <Col span="8" v-else>
                    <FormItem label="单位名称：" prop="companyId">
                        <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgInfo='setQueryCompanyId' :orgTree="true"
                                      :currentOrgId="dataToQuery.companyId" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
                    </FormItem>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label="项目名称：" prop="projectName" >
                        <Input v-model='dataToQuery.projectName' class="query-form-el"></Input>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="项目类型：" prop="content" >
                        <Select class='query-form-el' placeholder="请选择项目分类" type='text' v-model='dataToQuery.projectCateArrays' multiple>
                            <Option v-for="item in dictMap['EI-000001']" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8" v-if="modaleShow==2">
                    <FormItem label="计划执行情况：" prop="playImplementation" >
                        <Select class='w' placeholder="请选择计划执行情况" v-model='dataToQuery.playImplementation'>
                            <Option value="未执行">未执行</Option>
                            <Option value="执行中">执行中</Option>
                            <Option value="已完成">已完成</Option>
                            <Option value="已终止">已终止</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8" :offset="modaleShow==2?16:0">
                    <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                    <Button @click="reset1" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large" v-if="modaleShow==2" class="ivu-btn-add" icon="md-add"  @click="addInfo">新增</Button>
                    <Button type="primary" class="ivu-btn-add" icon="md-cloud-download" @click="exportForm('1')">导出详细</Button>
                    <Button type="primary" class="ivu-btn-add" icon="md-cloud-download" @click="exportForm('2')">导出汇总</Button>
                    <Button type="primary" class="ivu-btn-add" icon="md-cloud-download" @click="exportForm('3')">企业填报情况导出</Button>
                </Col>
            </Row>
        </Form>
        <Table ref='table' :height="tableHeight"  no-data-text="没有查询到相关数据!" @on-selection-change = 'getSelectRows' :loading='pageStatus.loading'
               border :columns="columns1"  :data="dataTable" >
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24" >
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
            </Col>
        </Row>
        <Modal :title="getModalTitle('环保投入计划(次年及临时)')" :transfer=false :mask-closable="false" v-model="dialogShow" v-if="dataToView && dialogShow" :width=800 :styles="{height:'620px'}"  class-name='limit-height-dialog' >
            <Row>
                <Col span="24">
                    <Form ref="dialogForm" :class="mode === 'view'?'modal-view-detail':'modal-form'" :show-message="false" :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"  :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?160:null">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='单位名称：' prop='companyId'>
                                    <div v-if="mode === 'view'">{{dataToView.companyName}}</div>
                                    <cascader-dom v-else ref='orgCascader' @setOrgInfo='setCompanyId' @setOrgname="setCompanyName" :orgTree="true" :currentOrgId = "dataToView.companyId" :setCurrentName="{label:dataToView.companyName,value:dataToView.companyId}" ></cascader-dom>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
							<Col span="23" v-if="mode !== 'view'">
							  <Alert type="error">11月1日至次年1月31日可填报次年年度计划</Alert>
							</Col>
                            <Col span="11">
                                <FormItem label="计划类型：" prop="playType" >
                                    <div v-if="mode === 'view'">{{dataToView.playType}}</div>
                                    <Select v-else class='w' placeholder="请选择计划类型" v-model='dataToView.playType'
                                            @on-change="planTypeChange">
                                        <Option value="年度计划" :disabled="![0,10,11].includes(new Date().getMonth())">年度计划</Option>
                                        <Option value="临时计划">临时计划</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='年度：' prop='rptPeroid'>
                                    <div v-if="mode === 'view'">{{ dataToView.rptPeroid }}</div>
                                    <Input v-else class='' placeholder="请选择年度" type='text' readonly v-model='dataToView.rptPeroid'></Input>
                                    <!--<DatePicker v-else class="w" placeholder="请选择年度" disabled v-model='dataToView.rptPeroidDate' type="year"></DatePicker>-->
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23" v-if="dataToView.playType == '临时计划'">
                                <FormItem label='新增计划原因：' prop='planReason'>
                                    <div v-if="mode === 'view'">{{ dataToView.planReason }}</div>
                                    <Input v-else class='' placeholder="请填写新增计划原因" type='text' show-word-limit maxlength="200" v-model='dataToView.planReason'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="项目类型：" prop="projectCategory" >
                                    <div v-if="mode === 'view'">{{this.dictMap['EI-000001'] && this.dictMap['EI-000001'][dataToView.projectCategory] && this.dictMap['EI-000001'][dataToView.projectCategory].codingName}}</div>
                                    <Select v-else class='w' placeholder="请选择项目分类" type='text' v-model='dataToView.projectCategory'>
                                        <Option v-for="item in dictMap['EI-000001']" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName }}</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='项目名称：' prop='projectName'>
                                    <div v-if="mode === 'view'">{{ dataToView.projectName }}</div>
                                    <Input v-else class='' placeholder="请填写项目名称" type='text' show-word-limit maxlength="100" v-model='dataToView.projectName'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='项目基本内容：' prop='content'>
                                    <div v-if="mode === 'view'">{{ dataToView.content }}</div>
                                    <Input v-else class='w' placeholder="请填写项目基本内容" type='textarea' v-model='dataToView.content'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='计划投资金额（万元）：' prop='investmentMoney'>
                                    <div v-if="mode === 'view'">{{ dataToView.investmentMoney }}</div>
                                    <InputNumber v-else class='w' placeholder="请填写计划投资金额（万元）" :min="0" type='text' v-model='dataToView.investmentMoney'
                                                 :formatter="value => `${value}万元`" :parser="value => value.replace('万元', '')"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='预计完成时间：' prop='expectedFinTime'>
                                    <div v-if="mode === 'view'">{{ dataToView.expectedFinTime ? dataToView.expectedFinTime.substr(0,10) : '' }}</div>
                                    <DatePicker v-else class="w" placeholder="请选择完成时间" v-model='dataToView.expectedFinTime' placement="top-start"
                                                :start-date="new Date().getMonth() === 0? new Date() :new Date(new Date().getFullYear()+1, 0, 1)"
                                                :options="{disabledDate(date) {return (dataToView.playType == '临时计划')?
                                                    (date && date.getFullYear()!=new Date().getFullYear()):
                                                    (date && date.valueOf() < (new Date().getMonth() === 0? new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()) : new Date(new Date().getFullYear()+1, 0, 1)))
                                                }}"></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="计划执行情况：" prop="playImplementation" >
                                    <div v-if="mode === 'view'">{{dataToView.playImplementation}}</div>
                                    <Select v-else class='w' placeholder="请选择计划执行情况" v-model='dataToView.playImplementation'>
                                        <Option value="未执行">未执行</Option>
                                        <Option value="执行中">执行中</Option>
                                        <Option value="已完成">已完成</Option>
                                        <Option value="已终止">已终止</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="11" v-if="dataToView.playImplementation == '已终止'">
                                <FormItem label='终止原因：' prop='stopReason'>
                                    <div v-if="mode === 'view'">{{ dataToView.stopReason }}</div>
                                    <Input v-else class='' placeholder="填写终止原因" type='text' show-word-limit maxlength="200" v-model='dataToView.stopReason'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11" v-else-if="dataToView.playImplementation == '已完成'">
                                <FormItem label='实际完成时间：' prop='realExpectedFinTime'>
                                    <div v-if="mode === 'view'">{{ dataToView.realExpectedFinTime ? dataToView.realExpectedFinTime.substr(0,10) : '' }}</div>
                                    <DatePicker v-else class="w" placeholder="请选择实际完成时间" v-model='dataToView.realExpectedFinTime' placement="top-start"
                                                :options="{disabledDate(date) {return date && date.valueOf() >= new Date();}}"></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11" v-else-if="dataToView.playImplementation == '执行中'">
                                <FormItem label='当前执行金额（万元）' prop='realInvestmentMoney'>
                                    <div v-if="mode === 'view'">{{ dataToView.realInvestmentMoney }}</div>
                                    <InputNumber v-else class='w' placeholder="请填写当前执行金额（万元）" :min="0" :max="dataToView.investmentMoney*1.5" type='text' v-model='dataToView.realInvestmentMoney'
                                                 :formatter="value => `${value}万元`" :parser="value => value.replace('万元', '')"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11" v-else></Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg" v-if="dataToView.playImplementation == '已完成'">
                            <Col span="11">
                                <FormItem label='实际投资金额（万元）：' prop='realInvestmentMoney'>
                                    <div v-if="mode === 'view'">{{ dataToView.realInvestmentMoney }}</div>
                                    <InputNumber v-else class='w' placeholder="请填写实际投资金额（万元）" :min="0" :max="dataToView.investmentMoney*1.5" type='text' v-model='dataToView.realInvestmentMoney'
                                                 :formatter="value => `${value}万元`" :parser="value => value.replace('万元', '')"></InputNumber>
                                </FormItem>
                            </Col>
                            <Col span="11">
                            </Col>
                        </Row>

                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='效果评价：' prop='effect'>
                                    <div v-if="mode === 'view'">{{ dataToView.effect }}</div>
                                    <Input v-else class='w' placeholder="请填写效果" type='text' v-model='dataToView.effect'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='填表人：' prop='registrant'>
                                    <div v-if="mode === 'view'">{{dataToView.createUserName}}</div>
                                    <Input v-else type='text' v-model='dataToView.createUserName' readonly></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='联系电话：' prop='creatorPhone'>
                                    <div v-if="mode === 'view'">{{dataToView.creatorPhone}}</div>
                                    <Input v-else type='text' v-model='dataToView.creatorPhone'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='填表时间：' prop='registTime'>
                                    <div v-if="mode === 'view'">{{renderViewDate(dataToView.createDate)}}</div>
                                    <DatePicker v-else type="date" placeholder="请选择日期" class="query-form-el" v-model='dataToView.createDate' readonly></DatePicker>
                                </FormItem>
                            </Col>
                        </Row>

                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-save' @click="submit('dialogForm')" >确定</Button>
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-cancel' @click="handleCancel" >取消</Button>
                <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
            </div>
        </Modal>
    </Layout>
</template>

<script>
    import {Api} from '@/api/index.js'
    var cascaderDom = () => import('@/components/cascader-dom.vue');
    import pageCommonFunction from '@/components/pageCommonFunction.js'
    export default {
        name: "auditForm",
        components:{cascaderDom},
        data(){
            return {
                ...this.createCommonDataField(),
                columns1:[],
                columns: [
                    { title: '序号', width: 80, fixed: 'left', align: 'center', render: (h, params) => {
                            if(params.row.id === '-1') return h('span', "汇总");
                            return h('span', (params.index - 1) + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                    }},
					{ key:'companyName',title: '单位名称', fixed: 'left', align: 'center' , minWidth :200},
                    { key:'rptPeroid',title: '年度', fixed: 'left', align: 'center', minWidth :80},
                    { key:'playImplementation',title: '计划执行情况',  align: 'center' , minWidth :110},
                    { key:'playType',title: '计划类型', align: 'center', minWidth :90},
                    { key:'projectCategory',title: '项目类型',  align: 'center', minWidth :140, render:(h, params)=>{
                            return h('span',  (this.dictMap['EI-000001'] && this.dictMap['EI-000001'][params.row.projectCategory] && this.dictMap['EI-000001'][params.row.projectCategory].codingName))
                        }, },
                    { key:'projectName',title: '项目名称',  align: 'center' , minWidth :140},
                    { key:'content',title: '项目基本内容',  align: 'center' , minWidth :160, tooltip:true},
                    { key:'investmentMoney',title: '计划投资金额（万元）',  align: 'center', minWidth :140 },
                    { key:'expectedFinTime',title: '预计完成时间',  align: 'center', render: this.renderCellDate, minWidth :120 },
                    { key:'realInvestmentMoney1',title: '当前执行金额（万元）',  align: 'center', minWidth :140,name:1},
                    { key:'realInvestmentMoney',title: '实际投资金额（万元）',  align: 'center', minWidth :140,name:2 },
                    { key:'realExpectedFinTime',title: '实际完成时间',  align: 'center', render: this.renderCellDate, minWidth :120,name:2  },
                    { key:'effect',title: '效果评价',  align: 'center' , minWidth :120, tooltip:true},
                    { key:'createUserName',title: '填表人',  align: 'center', width: 140  },
                    { key:'creatorPhone',title: '联系电话',  align: 'center', width: 140  },
                    { key:'createDate',title: '填表时间',  align: 'center', width: 120, render: this.renderCellDate },
                    {title: '操作', key: 'action', fixed: 'right', align: 'center', width:160,
                        render: (h, params) => {
                            if (params.row.id === '-1') {
                                return;
                            }
                            if (this.modaleShow == 1) {
                                return h('div', [
                                    h('A', {
                                        props: {type: 'primary', size: 'small'},
                                        style: {fontSize: '14px',},
                                        on: {
                                            click: () => {
                                                this.viewData(params);
                                            }
                                        }
                                    }, '详情'),
									// h('Divider', {props: {type: 'vertical'}}, ''),
									h('A', {
									    props: {type: 'primary', size: 'small'},
									    disabled: true,
									    style: {
											marginLeft: '6px',
											fontSize: '14px',
											display: this.currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined ||
											         this.currentUser.loginId === this.Common.admin ? 'inline-block' : 'none' 
										},
									    on: {
									        click: () => {
									            this.editData(params);
									        }
									    }
									}, '修改'),
                                ])
                            } else {
                                if ((params.row.playImplementation==='执行中'||params.row.playImplementation==='未执行')&&(this.currentUser.loginId === this.Common.admin || this.currentUser.userId === params.row.createUserId  || this.currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                                || this.currentUser.userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined)) {
                                    return h('div', [
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px',},
                                            on: {
                                                click: () => {
                                                    this.viewData(params);
                                                }
                                            }
                                        }, '详情'),
                                        h('Divider', {props: {type: 'vertical'}}, ''),
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            disabled: true,
                                            style: {fontSize: '14px'},
                                            on: {
                                                click: () => {
                                                    this.editData(params);
                                                }
                                            }
                                        }, '修改'),
                                        h('Divider', {props: {type: 'vertical'}}, ''),
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px', color: 'red'},
                                            on: {
                                                click: () => {
                                                    this.deleteData(params);
                                                }
                                            }
                                        }, '删除')
                                    ]);
                                } else {
                                    return h('div', [
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px',},
                                            on: {
                                                click: () => {
                                                    this.viewData(params);
                                                }
                                            }
                                        }, '详情'),
                                        h('Divider', {props: {type: 'vertical'}}, ''),
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px', color: '#c5c8ce'}
                                        }, '修改'),
                                        h('Divider', {props: {type: 'vertical'}}, ''),
                                        h('A', {
                                            props: {type: 'primary', size: 'small'},
                                            style: {fontSize: '14px', color: '#c5c8ce'}
                                        }, '删除')
                                    ]);
                                }
                            }
                        }}
                ],
                ruleCustom : {
                    companyId: [ { required: true, message: '请填写企业名称', trigger: 'change' } ],
                    projectCategory: [ { required: true, message: '请填写项目分类', trigger: 'change' } ],
                    rptPeroid: [ { required: true, message: '请填写年度', trigger: 'change', } ],
                    projectName: [ { required: true, message: '请填写项目分类', trigger: 'change' } ],
					creatorPhone: [{ pattern: /^((0\d{2,3}-\d{7,8})|(1[123456789]\d{9}))$/, required: true, message: '请填写正确的联系电话', trigger: 'change' }],

                    playType: [ { required: true, message: '请填写计划类型', trigger: 'change', } ],
                    planReason: [ { required: true, message: '请填写新增计划原因', trigger: 'change', } ],
                    playImplementation: [ { required: true, message: '请选择计划执行情况', trigger: 'change', } ],
                    stopReason: [ { required: true, message: '请填写终止原因', trigger: 'change', } ],
                    realExpectedFinTime: [ { required: true, message: '请填写实际完成时间', trigger: 'change',type:'date' } ],
                    realInvestmentMoney: [ { required: true, message: '请填写实际投资金额', trigger: 'change', type:'number'} ],
                    investmentMoney: [ { required: true, message: '请填写计划投资金额', trigger: 'change', type:'number'} ],
                    expectedFinTime: [ { required: true, message: '请填写计划完成时间', trigger: 'change',type:'date' } ],
                },
                tableHeight:10,
                dictMap: {},
                // api
                queryUrl:Api.queryEnRptInvestmentPlan,
                deleteUrl:Api.deleteEnRptInvestmentPlan,
                exportUrl:Api.exportEnRptInvestmentPlan,
                bthDeleteUrl:Api.batchDeleteEnRptInvestmentPlan,
                getUrl:Api.getEnRptInvestmentPlan,
                updateUrl:Api.updateEnRptInvestmentPlan,
                saveUrl:Api.saveEnRptInvestmentPlan,
                modaleShow: 1,
                twoLevel:[],
            }
        },
        async mounted() {
            this.columns1 = this.columns.filter(n=>n.name!=1)
            // [...this.columns]
            await this.$http.get(Api.queryDictBycode+"EI-000001",{}).then((res)=>{
                // 数据字典 list 转 map，方便调用
                this.dictMap = {
                    'EI-000001':this.dictListToMap(res.data.data['EI-000001'])
                }
            })
            this.$http.get(Api.quqeryTwoOrgInfo).then(res => {
                this.twoLevel=res.data.data
            })
            this.tableHeight = window.innerHeight - 325
            this.lowerStep(this.modaleShow)
        },
        methods:{
            ...pageCommonFunction,
            belongChange(value) {
                this.dataToQuery.belongOrgId = value.value
                this.dataToQuery.belongOrgName = value.label
            },
            deleteData(params) {
                this.deleteDateAjax(params);
            },
            exportForm(type){
                if (type === '1') {
                    this.exportUrl= Api.exportEnRptInvestmentPlan+'/details'
                    this.exportFormSubmit()
                }else if (type === '2') {
                    this.exportUrl= Api.exportEnRptInvestmentPlan
					if (!this.dataToQuery.belongOrgId) {
						this.dataToQuery.belongOrgName = this.currentUser.loginId === this.Common.admin
						                                ? this.currentUser.companyName
														:this.currentUser.twoLevelOrgName
					}
                    if (this.dataToQuery.yearDate) {
                        this.dataToQuery.year = this.dataToQuery.yearDate.getFullYear();
                        if (this.dataToQuery.projectCateArrays) {
                            this.dataToQuery.projectCategories = this.arrayToInFormat(this.dataToQuery.projectCateArrays)
                        }
                        this.exportFormSubmit()
                    } else {
                        this.$Message.error("导出时候年份必选")
                    }
                } else {
                    this.exportUrl= Api.exportEnRptInvestmentPlan + 'Company'
                    if (this.dataToQuery.yearDate) {
                        this.dataToQuery.year = this.dataToQuery.yearDate.getFullYear();
                        this.exportFormSubmit()
                    } else {
                        this.$Message.error("导出时候年份必选")
                    }
                }
            },
            query() {
                if(this.dataToQuery.projectCateArrays) {
                    this.dataToQuery.projectCategories = this.arrayToInFormat(this.dataToQuery.projectCateArrays)
                }
                if(this.dataToQuery.yearDate) {
                    this.dataToQuery.year = this.dataToQuery.yearDate.getFullYear();
                }else {
                    delete this.dataToQuery['year']
                }
                this.queryAjax();
            },
            submit(name) {
                let validateFields = Object.keys(this.ruleCustom).filter(n=>!['realInvestmentMoney','realExpectedFinTime','stopReason','planReason'].includes(n))
                if (this.dataToView.playType == '临时计划') {
                    validateFields.push('planReason')
                }
                if (this.dataToView.playImplementation=='执行中'){
                    this.dataToView.realExpectedFinTime=null
                    this.dataToView.stopReason=null
                    validateFields.push('realInvestmentMoney')
                }else if (this.dataToView.playImplementation=='已终止'){
                    this.dataToView.realInvestmentMoney=null
                    this.dataToView.realExpectedFinTime=null
                    validateFields.push('stopReason')
                }else if(this.dataToView.playImplementation=='已完成'){
                    validateFields.push('realInvestmentMoney')
                    validateFields.push('realExpectedFinTime')
                }
                else if(this.dataToView.playImplementation=='未执行'){
                    this.dataToView.realInvestmentMoney=null
                    this.dataToView.realExpectedFinTime=null
                    this.dataToView.stopReason=null
                }
                this.submitAjaxValidateField(name,this.dataToView,validateFields);
            },
            beforeEditDialogOpen(data) {
                // data.row.rptPeroidDate = new Date(data.row.rptPeroid + '-01-01');
                if(data.row.playImplementation === '执行中'){
                    data.row.realInvestmentMoney = data.row.realInvestmentMoney1
                }
                
            },
            beforeViewDialogOpen(data) {
                // data.row.rptPeroidDate = new Date(data.row.rptPeroid + '-01-01');
                if(data.row.playImplementation === '执行中'){
                    data.row.realInvestmentMoney = data.row.realInvestmentMoney1
                }
            },
            createEmptyDataToAdd(){
                return {
                    playType: [0,10,11].includes(new Date().getMonth()) ? '年度计划' : '临时计划',
                    investmentMoney:null,
                    realInvestmentMoney:null,
                    creatorPhone: this.currentUser.mobileNumber,
                    rptPeroid: (new Date().getFullYear()+ ([10,11].includes(new Date().getMonth())? 1 : 0)).toString(),
                    // rptPeroidDate: new Date()
                }
            },
            planTypeChange(val){
                if (this.mode === 'add') {
                    if (val=='临时计划'){
                        this.dataToView.rptPeroid=new Date().getFullYear().toString()
                    } else {
                        this.dataToView.planReason = null
                        let month = new Date().getMonth();
                        if (val=='年度计划' && month<1){
                            this.dataToView.rptPeroid=new Date().getFullYear().toString()
                        }else {
                            this.dataToView.rptPeroid=(new Date().getFullYear()+1).toString()
                        }
                    }
                }
            },
            reset1(){
                this.dataToQuery = {};
                if (this.$refs.queryOrgCascader) {
                    this.$refs.queryOrgCascader.resetCurrentOrg();
                }
                this.pagedata.currentPage=1
                this.lowerStep(this.modaleShow)
            },
            lowerStep(name) {
                this.modaleShow = name
                this.dataToQuery.modaleShow = name
                if (name == 1) {
                    this.dataToQuery.playImplementation ='已完成'
                }else{
                    delete this.dataToQuery['playImplementation']
                }
                this.setTableHeight()
                this.query();

            }
        },
        watch:{
            'modaleShow':function (name) {
                const columns = [...this.columns];
                const columns1 = []
                columns.forEach(item => {
                    if (name == 2) {
                        // if (item.name != 2) {
                            columns1.push(item)
                        // }
                    } else {
                        if (item.name != 1) {
                            columns1.push(item)
                        }
                    }
                })
                this.columns1 = columns1
            }
        },

    }
</script>

<style lang='css' scoped>

</style>
